//
//  UIView+SCBaseExt.m
//  SCFoundationKit
//
//  Created by Chao Sheng on 2023/10/13.
//

#import "UIApplication+SCBaseExt.h"

@implementation UIApplication (SCBaseExt)

- (UIWindow *)sc_keyWindow {

    if([self.delegate respondsToSelector:@selector(window)]) {
        if(self.delegate.window) {
            return self.delegate.window;
        }
    }

    if (@available(ios 13.0, *)) {
        UIWindowScene *windowScene = (UIWindowScene *)self.connectedScenes.allObjects[0];
        UIWindow *mainWindow = [windowScene valueForKeyPath:@"delegate.window"];
        if(mainWindow) {
            return mainWindow;
        } else {
            return windowScene.windows.lastObject;
        }
    } else {
/// #pragma clang diagnostic push 和 #pragma clang diagnostic pop 指令来控制编译器的警告输出。在这两个指令之间，编译器将忽略所有与指定警告相关的信息。
/// #pragma clang diagnostic ignored "-Wdeprecated-declarations" 指令告诉编译器忽略所有与废弃声明相关的警告信息
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        return self.keyWindow;
#pragma clang diagnostic pop
    }
    
}

@end
